Ext.onReady(function(){ 

Ext.QuickTips.init();

var pdStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=PDValue',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad: true
}); 

var fm = Ext.form;

//Gridpanel
var cm=new Ext.grid.ColumnModel([
{header:'流水号',dataIndex:'serialNo',hidden:true,
editor: new fm.TextField({allowBlank: false,editable:false,readOnly:true})
} ,
{header:'对应评级结果等级',
	dataIndex:'pdlevel',
	width:100,
	editor: new fm.ComboBox({
		store :pdStore,
		 valueField : 'code',
		 displayField : 'code',
		 typeAhead : true,
		 mode:'local', 
		triggerAction : 'all',
                allowBlank: false
            })
    },
{header:'得分下限',
		dataIndex:'modelScore',
		width:100,
		editor: new fm.TextField({
                allowBlank: false
            })	
}
]); 

var ds = new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'model/listModelLevel.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'serialNo'},
{name:'pdlevel'}, 
{name:'modelScore'}
]) 
}); 
ds.load(); 



var grid=new Ext.grid.EditorGridPanel({ 
id:'myCustomers',
renderTo:'panel',
stripeRows:true,//斑马线效果
title:'<div align="center">打分卡校验信息</div>', 
width:'400',
height:800, 
cm:cm,
store: ds, 
clicksToEdit: 2,
 tbar: [{
            text: '添加',
            handler : function(){
              
                var n = grid.getStore().getCount();// 获得总行数 
                var ModelLevel = grid.getStore().recordType;
                var ml = new ModelLevel({
                	serialNo:'',
                	pdlevel:'',
                	modelScore:''
                });
                grid.stopEditing();
                ds.insert(n, ml);
                grid.startEditing(0, 0);
            }
        },'-',
        {text:'提交',  handler:submitM},'-',
        {text:'取消',  handler:function(){grid.store.reload();ds.rejectChanges();}},
        ],
loadMask: { msg: "加载中..." }, 
viewConfig: {   forceFit:true   }  
                      
});

function submitM(){
	var mr=ds.getModifiedRecords();//获取所有更新过的记录  
     var recordCount=ds.getCount();//获取数据集中记录的数量  
     if(mr.length==0){  // 确认修改记录数量  
       alert("没有修改数据！");  
       return false;  
     }  
       
     var recordModStr="[";//这里以josn方式保存  
     for(var i=0;i<mr.length;i++){ 
    // recordModStr+=Ext.util.JSON.encode(mr[i].data);
    
      recordModStr+="{serialNo:"+"\""+mr[i].data["serialNo"]+"\""+",pdlevel:"+"\""+mr[i].data["pdlevel"]+"\""+",modelScore:"+mr[i].data["modelScore"]+"}";  
      if(i<mr.length-1)  
      	recordModStr+=",";  
    } 
     recordModStr+="]";
     
     Ext.Ajax.request({
		url:'model/addModelLevel.do',
		params : { newRecord: recordModStr},
		method:'POST',
		success:function(){
			Ext.MessageBox.alert("提示","操作成功！");
			ds.rejectChanges();
			grid.store.reload(); 
			recordModStr = "";
		},failure:function(){
			Ext.MessageBox.alert("提示", "操作失败！"); 
		}
	});  
}

/**
function afterEdit(obj){    //每次更改后，触发一次该事件  
	var row = obj.record;
	var col = obj.field;
	//alert(row.data.serialNo);
	//alert(col);
   //alert("orginalValue:"+obj.originalValue+",value:"+obj.value);  
   
	Ext.Ajax.request({
		url:'model/editQua.do',
		params : { serialNo: row.data.serialNo,
			field:col, 
			originalValue:obj.originalValue, 
			modifiedValue:obj.value
		},
		method:'POST',
		success:function(){
			Ext.MessageBox.alert("提示","修改成功！");
			grid.store.reload(); 
		},failure:function(){
			Ext.MessageBox.alert("提示", "修改失败！"); 
		}
	});
 
}  
grid.on("afteredit", afterEdit, grid);  
*/

}); 